package zhuyun.code.horizontalscrollview

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView

/**
 * @author: Administrator
 * @date: 2022/1/1
 */
class ListViewAdapter(private val context:Context, private val listViewName:String):BaseAdapter() {
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var itemView:View
        var viewHolder:ViewHolder
        if(convertView == null){
            itemView = LayoutInflater.from(context).inflate(R.layout.item_listview_layout,null)
            viewHolder = ViewHolder()
            viewHolder.textView = itemView.findViewById(R.id.textView)
            itemView!!.tag = viewHolder
        } else {
            itemView = convertView
            viewHolder = itemView.tag as ViewHolder

        }
        viewHolder.textView.text = "$listViewName---$position"
        return itemView
    }

    override fun getItem(position: Int): Any {
        return position
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getCount(): Int {
        return 100
    }
    class ViewHolder{
        lateinit var textView: TextView
    }
}